//现在可能是超级赛亚人一 口才 掌控力 人脉都比曾经的自己要号很多 ， 但是不能自满 不能放弃努力，往后还会有超级赛亚人二、超级三亚人三
//超级赛亚人之神红、蓝 自在极易...一路打怪升级 一路踏实向前...
#include <iostream>
#include <map>
#include <memory>
using namespace std;

class StrVec
{
public:
	StrVec():
	elements(nullptr),first_free(nullptr),cap(nullptr){}
	StrVec(const StrVec&);
	StrVec& operator=(const StrVec&);
	~StrVec();
	void push_back(const string &);
	size_t size() const{ return first_free - elements;}
	size_t capacity() const{ return cap - elements;}
	string *begin() const { return elements;}
	string *end() const { return first_free;}
	//...
	
private:
	static allcator<string> alloc;
	void chk_n_alloc(){
		if(size() == capacity())
			reallocate();
	}
	pair<string*,string*> alloc_n_copy
	(const string*,const string*);
	void free();
	void reallocate();
	string *elements; //
	string *first_free;
	string *cap;
};

void StrVec::push_back(const string& rhs)
{
	chk_n_alloc();
	// create a copy of s
	alloc.construct(first_free++,s);
}

pair<string*,string*> 
StrVec::alloc_n_copy(const string *b,const string* e){
	auto data = alloc.allocate(e - b);

	// initialize and return a pair 
	return {data,uninitialized_copy(b,e,data)};
}

// free the space by allocator
void StrVec::free(){
	if(elements){
		for(auto p = first_free ; p != elements; 
			alloc.destroy(--p));
		alloc.deallocate(elements,cap - elements); 
	}
}

StrVec::StrVec(const StrVec &rhs){
	auto newdata = alloc_n_copy(s.begin() , s.end());
	elements = newdata.first;
	first_free = cap = newdata.second;
}

StrVec &StrVec::operator=(const StrVec &rhs){
	auto data = alloc_n_copy(rhs.begin(), rhs.end());
	free();
	elements = data.first;
	first_free = cap = data.second;
	return *this;
}

void StrVec::reallocate(){
	auto newcapacity = size() ? 2*size() : 1;
	auto newdata = alloc.allocate(newcapacity); // allocaet raw memory
	auto dest = newdata;
	auto elem = elements;

	for(size_t i = 0 ; i != size() ; ++i){
		alloc.construct(dest++,std::move(*elem++));
	}
	free();
	elements = newedata;
	first_free = dest;
	cap = elements + newcapacity; 
}
int main(int argc, char const *argv[])
{
	
	return 0;
}
